package cn.itcast.nems.studentrecord.dto.change;

import cn.itcast.nems.studentrecord.enumeration.StudentRecordSourceEnum;
import cn.itcast.nems.studentrecord.enumeration.StudentRecordStateEnum;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 学籍变更时用的数据对象；如果学籍变更只涉及一个班（如：退学）原班级和目标班值一样
 *
 * @author liyong
 * create: 2023-11-21 16:02:06
 **/
@Getter
@Setter
@ToString(callSuper = true)
public class StudentRecordChangeDTO extends AbstractStudentRecordChangeDTO {

    /**
     * 学员ID
     */
    private int studentId;

    /**
     * 目标班级原始价格
     */
    private Integer targetClazzPrice;

    /**
     * 目标班级应付金额
     */
    private Integer targetClazzAmountDue;
    /**
     * 目标班级实际应付金额
     */
    private Integer targetClazzActualAmountDue;
    /**
     * 目标班级转移费用(从其他班转入的金额)
     */
    private Integer targetClazzTransferAmount;
    /**
     * 目标班级优惠金额
     */
    private Integer targetClazzDiscountAmount;

    /**
     * 目标班级状态
     */
    private StudentRecordStateEnum targetClazzState = StudentRecordStateEnum.PENDING;

    /**
     * 目标班优惠信息
     */
    private List<StudentRecordChangeDiscountDTO> discounts;

    /**
     * 学籍备注
     */
    private String remark;

    /**
     * 创建目标班学籍参数
     *
     * @return 创建学籍参数
     */
    public StudentRecordCreateDTO createTargetStudentRecordDTO(StudentRecordSourceEnum source) {
        StudentRecordCreateDTO result = new StudentRecordCreateDTO();
        result.setSource(source);
        result.setReferenceType(super.getJournalType());
        result.setReferenceId(this.getJournalId());
        result.setReferenceLineId(this.getJournalLineId());
        result.setStudentId(this.getStudentId());
        result.setClazzId(this.getTargetClazzId());
        result.setClazzName(this.getTargetClazzName());
        result.setPrice(this.getTargetClazzPrice());
        result.setAmountDue(this.getTargetClazzAmountDue());
        result.setActualAmountDue(this.getTargetClazzActualAmountDue());
        result.setDiscountAmount(this.getTargetClazzDiscountAmount());
        result.setTransferFromAmount(this.getTargetClazzTransferAmount());
        result.setAdjustmentAmount(0);
        result.setPaidAmount(0);
        result.setRefundAmount(0);
        if (StringUtils.hasText(this.getOriginStudentRecordId())) {
            result.setAssociatedRecordId(this.getOriginStudentRecordId());
        }
        result.setRemark(this.getRemark());
        result.setDiscounts(this.getDiscounts());
        result.setInDate(this.getTargetClazzInDate().atStartOfDay());
        if (this.getTargetClazzState() != null) {
            result.setState(this.getTargetClazzState());
        }
        return result;
    }
}
